package code.google.jcustomize;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

class ConfigItem {
    public final static String ACTION_CHANGE    = "CHANGE";
    public final static String ACTION_APPEND    = "APPEND";
    public final static String ACTION_REMOVE    = "REMOVE";
    private String path;
    private String value;
    private List condVals = Collections.EMPTY_LIST;
    private List condTest = Collections.EMPTY_LIST;
    private boolean required;
    private String condition;
    private String replace;
    private String action = ACTION_CHANGE;
    private Object opt;
    
    public String getPath() {
        return path;
    }
    
    public void setPath(String path) {
        this.path = path;
    }
    
    public String getValue() {
        return value;
    }
    
    public void setValue(String value) {
        this.value = value;
    }

    public boolean isRequired() {
        return required;
    }

    public void setRequired(boolean required) {
        this.required = required;
    }

    public String getAction() {
        return action;
    }

    public void setAction(String action) {
        if (ACTION_CHANGE.equalsIgnoreCase(action))
            this.action = ACTION_CHANGE;
        else if (ACTION_APPEND.equalsIgnoreCase(action))
            this.action = ACTION_APPEND;
        else if (ACTION_REMOVE.equalsIgnoreCase(action))
            this.action = ACTION_REMOVE;
        else throw new IllegalArgumentException("Invalid action value '"+action+"'");
    }

    public String getCondition() {
        return condition;
    }

    public void setCondition(String condition) {
        this.condition = condition;
    }
    
    public void addConditionValue(String val, String cond) {
        if (condVals == Collections.EMPTY_LIST) {
            condVals = new ArrayList();
            condTest = new ArrayList();
        }
        condVals.add(val);
        condTest.add(cond);
    }
    
    public List getConditionVals() {
        return condVals;
    }
    
    public List getConditionTests() {
        return condTest;
    }

    public String getReplace() {
        return replace;
    }

    public void setReplace(String replace) {
        this.replace = replace;
    }

    public void setOpt(Object opt) {
        this.opt = opt;
    }

    public Object getOpt() {
        return opt;
    }
}
